/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

#define _DEF_CCY_CODE
#define _ZZDEBUG
#define _PROJ_DC

#region Using directives
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;

using Muki.Framework.Util;
using Muki.Framework.Business;
using Muki.Framework;
using Muki.UserDefine;
using Muki.Entity;
using Dot.StreamObject;

#endregion

namespace Muki.UserPanel
{
	public class UID02812BM:BLogic
	{
		public UID02812BM()
		{
			objDefault.UID_CODE    ="UID02812B";
		}

		public void Initialize()
		{
			objDefault.ZZLOGON_SSD = this.ZZLOGON_SSD;
			objDefault.Trans       = this.Trans;
			objDefault.ZZLOGON_ID  = this.ZZLOGON_ID;

			_Convert.ZZLOGON_SSD = this.ZZLOGON_SSD;
			_Convert.Trans       = this.Trans;

			_DataPermission.ZZLOGON_SSD = this.ZZLOGON_SSD;
			_DataPermission.Trans       = this.Trans;
			_DataPermission.TABLE_NAME  = "MIRDTLM";
			_DataPermission.ZZLOGON_ID  = this.ZZLOGON_ID;
			_DataPermission.DataAccessRight();

			_DocsPermission.ZZLOGON_SSD  = this.ZZLOGON_SSD;
			_DocsPermission.Trans        = this.Trans;

			_Setting.ZZLOGON_ID = this.ZZLOGON_ID;
			_Setting.Trans      = this.Trans;

		}

		public UID02812BE Verify(UID02812BE _Entity)
		{

						_Entity.MI_DT=_Entity.MI_DT.Trim();

					if (Util.IsNullOrEmpty(_Entity.TRANS_WO_DT))
					{
						_Entity.Exceptions.Add(new LogisticException("TRANS_WO_DT","DataMiss"));
					}

					if (Util.IsNullOrEmpty(_Entity.TRANS_QTY))
					{
						_Entity.Exceptions.Add(new LogisticException("TRANS_QTY","DataMiss"));
					}

				// Relation MIRHDTM
			if (!Util.IsNullOrEmpty(_Entity.MI_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(MIRHDTMEntity));//MIRHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("MI_NO",_Entity.MI_NO);
				_DataPermission.TABLE_NAME="MIRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("MI_NO","DataNotFd",_Entity.MI_NO));
			}else{

					MIRHDTMEntity objVMIRHDTMEntity=(MIRHDTMEntity)objEntityContainer[0];
					if (objVMIRHDTMEntity.Verified)
					{
if ( _Entity.COMP_CODE==""){
						 _Entity.COMP_CODE=objVMIRHDTMEntity.COMP_CODE;
}
						 _Entity.MI_NO=objVMIRHDTMEntity.MI_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("MI_NO","DataNotFd",_Entity.MI_NO));
					}
			}
			}
//MIRHDTM

				// Relation WORDTLM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_DT))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORDTLMEntity));//工作单明细
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_DT",_Entity.TRANS_WO_DT);
				_DataPermission.TABLE_NAME="WORDTLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_WO_DT","DataNotFd",_Entity.TRANS_WO_DT));
			}else{

					WORDTLMEntity objVWORDTLMEntity=(WORDTLMEntity)objEntityContainer[0];
					if (objVWORDTLMEntity.Verified)
					{
if ( _Entity.ITEM_NO==""){
						 _Entity.ITEM_NO=objVWORDTLMEntity.ITEM_NO;
}
						 _Entity.TRANS_WO_DT=objVWORDTLMEntity.WO_DT;
if ( _Entity.TRANS_WO_NO==""){
						 _Entity.TRANS_WO_NO=objVWORDTLMEntity.WO_NO;
}

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_WO_DT","DataNotFd",_Entity.TRANS_WO_DT));
					}
			}
			}
//WORDTLM

				// Relation PARTBLM
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
			}else{

					PARTBLMEntity objVPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objVPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objVPARTBLMEntity.ITEM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
					}
			}
			}
//PARTBLM

				// Relation PARTBLM
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
			}else{

					PARTBLMEntity objVPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objVPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objVPARTBLMEntity.ITEM_NO;

					}else{
						_Entity.Exceptions.Add(new LogisticException("ITEM_NO","DataNotFd",_Entity.ITEM_NO));
					}
			}
			}
//PARTBLM

				// Relation WHLOCTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX1))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WHLOCTMEntity));//仓位资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("LOC_CODE",_Entity.TRANS_UDFX1);
			objCondition.Equals("WH_CODE",_Entity.WH_CODE);
				_DataPermission.TABLE_NAME="WHLOCTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX1","DataNotFd",_Entity.TRANS_UDFX1));
			}else{

					WHLOCTMEntity objVWHLOCTMEntity=(WHLOCTMEntity)objEntityContainer[0];
					if (objVWHLOCTMEntity.Verified)
					{
						 _Entity.TRANS_UDFX1=objVWHLOCTMEntity.LOC_CODE;
						 _Entity.WH_CODE=objVWHLOCTMEntity.WH_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX1","DataNotFd",_Entity.TRANS_UDFX1));
					}
			}
			}
//WHLOCTM

				// Relation COLORTM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX3))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(COLORTMEntity));//颜色码资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("COLOR_CODE",_Entity.TRANS_UDFX3);
				_DataPermission.TABLE_NAME="COLORTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX3","DataNotFd",_Entity.TRANS_UDFX3));
			}else{

					COLORTMEntity objVCOLORTMEntity=(COLORTMEntity)objEntityContainer[0];
					if (objVCOLORTMEntity.Verified)
					{
						 _Entity.TRANS_UDFX3=objVCOLORTMEntity.COLOR_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX3","DataNotFd",_Entity.TRANS_UDFX3));
					}
			}
			}
//COLORTM

				// Relation SIZECDM
			if (!Util.IsNullOrEmpty(_Entity.TRANS_UDFX4))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(SIZECDMEntity));//尺寸资料
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("SIZE_CODE",_Entity.TRANS_UDFX4);
				_DataPermission.TABLE_NAME="SIZECDM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

			if (objEntityContainer.Count==0)
			{
				_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX4","DataNotFd",_Entity.TRANS_UDFX4));
			}else{

					SIZECDMEntity objVSIZECDMEntity=(SIZECDMEntity)objEntityContainer[0];
					if (objVSIZECDMEntity.Verified)
					{
						 _Entity.TRANS_UDFX4=objVSIZECDMEntity.SIZE_CODE;

					}else{
						_Entity.Exceptions.Add(new LogisticException("TRANS_UDFX4","DataNotFd",_Entity.TRANS_UDFX4));
					}
			}
			}
//SIZECDM

				return _Entity;
		}

		public List<UID02812BE> Verify(List<UID02812BE> _Entitys)
		{
			List<UID02812BE> _New_Entitys=new List<UID02812BE>();

			foreach (UID02812BE _Entity in _Entitys) 
			{
				_New_Entitys.Add(Verify(_Entity));
			}
			return _New_Entitys;
		}

		public UID02812BE Default(UID02812BE _Entity)
		{

						_Entity.MI_DT=objDefault.getDefault("MI_DT",_Entity.MI_DT);
						_Entity.COMP_CODE=objDefault.getDefault("COMP_CODE",_Entity.COMP_CODE);
						_Entity.SERIAL_NO=objDefault.getDefault("SERIAL_NO",_Entity.SERIAL_NO);
						_Entity.TRANS_CODE=objDefault.getDefault("TRANS_CODE",_Entity.TRANS_CODE);
						_Entity.WH_CODE=objDefault.getDefault("WH_CODE",_Entity.WH_CODE);
						_Entity.TRANS_DATE=objDefault.getDefault("TRANS_DATE",_Entity.TRANS_DATE);
						_Entity.TRANS_WO_DT=objDefault.getDefault("TRANS_WO_DT",_Entity.TRANS_WO_DT);
						_Entity.TRANS_WO_NO=objDefault.getDefault("TRANS_WO_NO",_Entity.TRANS_WO_NO);
						_Entity.ITEM_NO=objDefault.getDefault("ITEM_NO",_Entity.ITEM_NO);
						_Entity.ITEM_NAME01=objDefault.getDefault("ITEM_NAME01",_Entity.ITEM_NAME01);
						_Entity.UOM_CODE=objDefault.getDefault("UOM_CODE",_Entity.UOM_CODE);
						_Entity.ITEM_NAME02=objDefault.getDefault("ITEM_NAME02",_Entity.ITEM_NAME02);
						_Entity.TRANS_UDFX1=objDefault.getDefault("TRANS_UDFX1",_Entity.TRANS_UDFX1);
						_Entity.TRANS_UDFX3=objDefault.getDefault("TRANS_UDFX3",_Entity.TRANS_UDFX3);
						_Entity.TRANS_UDFX4=objDefault.getDefault("TRANS_UDFX4",_Entity.TRANS_UDFX4);
						_Entity.TRANS_QTY=objDefault.getDefault("TRANS_QTY",_Entity.TRANS_QTY);
						_Entity.REFX_NO=objDefault.getDefault("REFX_NO",_Entity.REFX_NO);
						_Entity.TRANS_RMK=objDefault.getDefault("TRANS_RMK",_Entity.TRANS_RMK);

					// WriteDefault MIRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.MI_NO="+_Entity.MI_NO);
			if (!Util.IsNullOrEmpty(_Entity.MI_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(MIRHDTMEntity));//MIRHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("MI_NO",_Entity.MI_NO);
				_DataPermission.TABLE_NAME="MIRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"MIRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					MIRHDTMEntity objDMIRHDTMEntity=(MIRHDTMEntity)objEntityContainer[0];
					if (objDMIRHDTMEntity.Verified)
					{
						 _Entity.MI_NO=objDMIRHDTMEntity.MI_NO;
						 _Entity.COMP_CODE=objDMIRHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDMIRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDMIRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDMIRHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

					// WriteDefault WORDTLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_DT="+_Entity.TRANS_WO_DT);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_DT))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORDTLMEntity));//工作单明细
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_DT",_Entity.TRANS_WO_DT);
				_DataPermission.TABLE_NAME="WORDTLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORDTLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORDTLMEntity objDWORDTLMEntity=(WORDTLMEntity)objEntityContainer[0];
					if (objDWORDTLMEntity.Verified)
					{
						 _Entity.TRANS_WO_DT=objDWORDTLMEntity.WO_DT;
						 _Entity.ITEM_NO=objDWORDTLMEntity.ITEM_NO;
						 _Entity.TRANS_WO_NO=objDWORDTLMEntity.WO_NO;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

				return _Entity;
		}

		public List<UID02812BE> Default(List<UID02812BE> _Entitys)
		{
			List<UID02812BE> _New_Entitys=new List<UID02812BE>();
			foreach (UID02812BE _Entity in _Entitys) 
			{
				_New_Entitys.Add(Default(_Entity));
			}
			return _New_Entitys;
		}

		public UID02812BE Search(VContexts _VContexts,UID02812BE _Entity)
		{

			if (_DocsPermission.AccessRight("UID02812B", this.ZZLOGON_ID, "ACCESS")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02812B","NotAccessRight", this.ZZLOGON_ID));
				return _Entity;
			}

			ZZSQLStatement  _SQLStatement = new ZZSQLStatement();

			_SQLStatement.Trans         = this.Trans;
			_SQLStatement.UID_CODE      = "UID02812B";
			_SQLStatement.ZZLOGON_SSD   = this.ZZLOGON_SSD;
			_SQLStatement.ZZLOGON_LANG  = this.ZZLOGON_LANG;
			_SQLStatement.DbName        = this.DbName;
			_SQLStatement.Process("QID02812B");

			ZZQLite oZZQLite = _SQLStatement.oZZQLite;

			if (_VContexts.getValue("T1")!="" && _VContexts.getValue("V1")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T1"), _VContexts.getValue("V1"));
			}
			if (_VContexts.getValue("T2")!="" && _VContexts.getValue("V2")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T2"), _VContexts.getValue("V2"));
			}
			if (_VContexts.getValue("T3")!="" && _VContexts.getValue("V3")!="")
			{
				oZZQLite.AddXWhereClause("", _VContexts.getValue("T3"), _VContexts.getValue("V3"));
			}

			if (!Util.IsNullOrEmpty(_VContexts.getValue("lookup")))
			{
				oZZQLite.AddXWhereClause("A", "", _VContexts.getValue("lookup"));
			}

						_VContexts.setValue("TT1","MIRDTLM.MI_NO");
						_VContexts.setValue("VV1",_Entity.MI_NO);
						oZZQLite.AddWhereClause("MIRDTLM", "MI_NO", _Entity.MI_NO);

			oZZQLite.Condition=_VContexts.getValue("Condition");
			oZZQLite.Make();

			int _AbsolutePage = _VContexts.getInteger("AbsolutePage");
			int _PageSize     = _VContexts.getInteger("ZZPageSize");
			int _Restrict     = _VContexts.getInteger("Restrict");
			int _TotalPages   = 0;

			_Setting.Trans      = this.Trans;

			if (_Restrict == 0)
			{
				_Restrict=30;
			}

			if (_PageSize <= 0)
			{
				_PageSize=_Setting.getInteger("ZZPageSize","20");
			}

				QueryRows RsMIRDTLM   = new QueryRows(this.Trans);
			RsMIRDTLM.CommandText = oZZQLite.SQLStatement;
			RsMIRDTLM.Top         = _Restrict;
			RsMIRDTLM.Skip        = (_AbsolutePage-1)*_PageSize;
			RsMIRDTLM.Limit       = _PageSize;
			RsMIRDTLM.CountAll    = true;
			RsMIRDTLM.Open();

			if (_PageSize <= 0)
			{
				_TotalPages   = RsMIRDTLM.RecordCount;
				_PageSize = RsMIRDTLM.RecordCount;
			}
			else
			{
				_TotalPages= RsMIRDTLM.RecordCount / _PageSize;
			}
			if (RsMIRDTLM.RecordCount > (RsMIRDTLM.RecordCount / _PageSize) * _PageSize)
			{
				_TotalPages = _TotalPages+ 1;
			}

			if (_AbsolutePage <= 0)
			{
				_AbsolutePage = 1;
			}

			if (_AbsolutePage > _TotalPages)
			{
				_AbsolutePage = _TotalPages;
			}

			Wxf _Wxf  = new Wxf();

			_Wxf.XDeclareStart();
			foreach(AttributeMapping _AttributeMapping in oZZQLite.AttributeMappings)
			{
				if (_AttributeMapping.STATUS_CODE != "HIDDEN")
				{
					_Wxf.XDeclare(_AttributeMapping);
				}
			}
			_Wxf.XDeclareFinal();

			_Wxf.Variable("ZZPageSize",_PageSize);
			_Wxf.Variable("ZZPages",_TotalPages);
			_Wxf.Variable("USQL_CODE","QID02812B");

			while (!RsMIRDTLM.EOF)
			{
				string cPickUpData   = "";
				object cValue;

				_Wxf.AddNew();
				int i=0;
				foreach(AttributeMapping _AttributeMapping in oZZQLite.AttributeMappings)
				{

					cValue = RsMIRDTLM[i];

					if (_AttributeMapping.STATUS_CODE != "HIDDEN")
					{
						_Wxf[_AttributeMapping.Name] = cValue;
					}

					if (_AttributeMapping.PrimaryKey)
					{
						if (cPickUpData != "")
						{
							cPickUpData = cPickUpData + "|";
						}
						cPickUpData = cPickUpData + ZZGeneral.Base64Encoder(_AttributeMapping.ColumnName + "=" + cValue);
					}
					i++;
				}

				_Wxf.PK_DATA   = cPickUpData;
				_Wxf.Update();

				RsMIRDTLM.MoveNext();
			}
			RsMIRDTLM.Close();

			_Entity.Wxf=_Wxf;

			return _Entity;
		}

		public UID02812BE Retrieves(VContexts _VContexts,UID02812BE _Entity)
		{
			if (_DocsPermission.AccessRight("UID02812B", this.ZZLOGON_ID, "ACCESS")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02812B","NotAccessRight",this.ZZLOGON_ID));
				return _Entity;
			}

			List<UID02812BE> _New_Entitys=new List<UID02812BE>();

				CriteriaRetrieve objRetrieveMIRDTLMEntity=new CriteriaRetrieve(typeof(MIRDTLMEntity));

			objRetrieveMIRDTLMEntity.Top=1;
			objCondition=objRetrieveMIRDTLMEntity.NewCondition();

			bool ZZOrderByAsc=_Setting.getBoolean("ZZOrderByAsc","YES");
			switch (_VContexts.getValue("UDEF_CODE"))
			{
				case "MF":
					{
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",ZZOrderByAsc);
						break;
					}
				case "ML":
					{
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",!ZZOrderByAsc);
						break;
					}
				case "MN":
					{
						if (ZZOrderByAsc)
						{
							objCondition.GreaterThan("MI_DT",_Entity.MI_DT);
						}else{
							objCondition.LessThan("MI_DT",_Entity.MI_DT);
						}
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",ZZOrderByAsc);
						break;
					}
				case "MP":
					{
						if (ZZOrderByAsc)
						{
							objCondition.LessThan("MI_DT",_Entity.MI_DT);
						}else{
							objCondition.GreaterThan("MI_DT",_Entity.MI_DT);
						}
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",!ZZOrderByAsc);
						break;
					}
				case "CANCEL":
					{
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",ZZOrderByAsc);
						_Entity.DATA_STATUS_CODE="Verified";
						break;
					}
				case "LOOKUP":
					{
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",ZZOrderByAsc);
						break;
					}

				case "ACTIVETAB":
					{
								if (_Entity.MI_DT != "")
								{
									objCondition.Equals("MI_DT", _Entity.MI_DT);
								}

						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",ZZOrderByAsc);
						break;
					}

				case "READ":
					{
								objCondition.Equals("MI_DT", _Entity.MI_DT);
						break;
					}					
				default:
					{
								if (_Entity.MI_DT != "")
								{
									objCondition.Equals("MI_DT", _Entity.MI_DT);
								}
						objRetrieveMIRDTLMEntity.OrderBy("MI_DT",ZZOrderByAsc);

						break;
					}
			}

			//filter by quick look
			string _LOOUP_COLUMN_NAME=";MIRDTLM.MI_NO;MIRDTLM.MI_DT;MIRDTLM.TRANS_WO_DT;MIRDTLM.TRANS_WO_NO;MIRDTLM.ITEM_NO;MIRDTLM.TRANS_UDFX1;MIRDTLM.TRANS_UDFX3;MIRDTLM.TRANS_UDFX4;MIRDTLM.REFX_NO;MIRDTLM.TRANS_RMK";
			string lookup=_VContexts.getValue("lookup");
			_LOOUP_COLUMN_NAME=_LOOUP_COLUMN_NAME+";";
			if (lookup!="")
			{
				Condition _Condition2=objCondition.NewCondition(" AND ");
				foreach (string s in _LOOUP_COLUMN_NAME.Split(new char[] { ';' }))
				{
					if (!string.IsNullOrEmpty(s))
					{
						Condition OrCondition=_Condition2.NewCondition();
						OrCondition.Expression(s,lookup);
					}
				}
			}

			//filter by filters

				//filter by AccessConditions
				_DataPermission.AccessCondition(objCondition);

						objCondition.Equals("MI_NO", _Entity.MI_NO);

			MIRDTLMEntity objMIRDTLMs=(MIRDTLMEntity)this.Trans.RetrieveEntity(objRetrieveMIRDTLMEntity);

			ZZTrace.Debug(ZFILE_NAME,"SELECT="+objRetrieveMIRDTLMEntity.SELECTClause);

			if (objMIRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="MN")
			{
				_Entity.Exceptions.Add(new LogisticException("MI_DT","DataEOF"));
				return _Entity;
			}else if (objMIRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="MP")
			{
				_Entity.Exceptions.Add(new LogisticException("MI_DT","DataBOF"));
				return _Entity;
			}else if (objMIRDTLMs==null && (_VContexts.getValue("UDEF_CODE")=="MF" || _VContexts.getValue("UDEF_CODE")=="ML") )
			{
				_Entity.Exceptions.Add(new LogisticException("MI_DT","DataBlank"));
				return _Entity;
			}else if (objMIRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="LOOKUP")
			{
				/*
				 *if (this.COLUMN_REFX.IndexOf(";")>=0)
				 *{
				 *}else{
				 *    string _T_COLUMN_REFX=this.COLUMN_REFX;
				 *    if (_T_COLUMN_REFX.IndexOf('.') > 0)
				 *    {
				 *        string[] s = _T_COLUMN_REFX.Split(new char[] { '.' });
				 *        _T_COLUMN_REFX=s[1];
				 *    }
				 *    _Entity.Exceptions.Add(new LogisticException(_T_COLUMN_REFX,"DataNotFd","DataBlank"));
				 *    return _Entity;
				 *}
				 */
			}else if (objMIRDTLMs==null && _VContexts.getValue("UDEF_CODE")=="ACTIVETAB")
			{
				//throw new LogisticException("MI_DT","Activetab","");
				//this.Default(_Entity);
			}else if (objMIRDTLMs==null)
			{
				//this.Default(_Entity);
			}else{
				MIRDTLMEntity objMIRDTLMEntity = objMIRDTLMs;
					ZZTrace.MUKI_DEBUG_LOG=true;
						_Entity.MI_NO=objMIRDTLMEntity.MI_NO;
						_Entity.MI_DT=objMIRDTLMEntity.MI_DT;
						_Entity.SERIAL_NO=objMIRDTLMEntity.SERIAL_NO;
						_Entity.TRANS_WO_DT=objMIRDTLMEntity.TRANS_WO_DT;
						_Entity.TRANS_WO_NO=objMIRDTLMEntity.TRANS_WO_NO;
						_Entity.ITEM_NO=objMIRDTLMEntity.ITEM_NO;
						_Entity.TRANS_UDFX1=objMIRDTLMEntity.TRANS_UDFX1;
						_Entity.TRANS_UDFX3=objMIRDTLMEntity.TRANS_UDFX3;
						_Entity.TRANS_UDFX4=objMIRDTLMEntity.TRANS_UDFX4;
						_Entity.TRANS_QTY=objMIRDTLMEntity.TRANS_QTY;
						_Entity.REFX_NO=objMIRDTLMEntity.REFX_NO;
						_Entity.TRANS_RMK=objMIRDTLMEntity.TRANS_RMK;

				_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objMIRDTLMEntity.ZADD_DATE);
_Entity.UZADD_USER     =objMIRDTLMEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objMIRDTLMEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objMIRDTLMEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objMIRDTLMEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objMIRDTLMEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objMIRDTLMEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objMIRDTLMEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objMIRDTLMEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objMIRDTLMEntity.ZSECURITY_CODE6;

					// WriteDefault MIRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.MI_NO="+_Entity.MI_NO);
			if (!Util.IsNullOrEmpty(_Entity.MI_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(MIRHDTMEntity));//MIRHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("MI_NO",_Entity.MI_NO);
				_DataPermission.TABLE_NAME="MIRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"MIRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					MIRHDTMEntity objDMIRHDTMEntity=(MIRHDTMEntity)objEntityContainer[0];
					if (objDMIRHDTMEntity.Verified)
					{
						 _Entity.MI_NO=objDMIRHDTMEntity.MI_NO;
						 _Entity.COMP_CODE=objDMIRHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDMIRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDMIRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDMIRHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

					// WriteDefault WORDTLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_DT="+_Entity.TRANS_WO_DT);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_DT))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORDTLMEntity));//工作单明细
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_DT",_Entity.TRANS_WO_DT);
				_DataPermission.TABLE_NAME="WORDTLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORDTLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORDTLMEntity objDWORDTLMEntity=(WORDTLMEntity)objEntityContainer[0];
					if (objDWORDTLMEntity.Verified)
					{
						 _Entity.TRANS_WO_DT=objDWORDTLMEntity.WO_DT;
						 _Entity.ITEM_NO=objDWORDTLMEntity.ITEM_NO;
						 _Entity.TRANS_WO_NO=objDWORDTLMEntity.WO_NO;

					}else{
					}
			}else{
			}
			}

					// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

					_Entity.DATA_STATUS_CODE="Verified";
			}
				return _Entity;
		}

		public  UID02812BE AddNew(UID02812BE _Entity)
		{

			ZZTrace.Debug(ZFILE_NAME,"ZZLOGON_ID="+this.ZZLOGON_ID);

			if (_DocsPermission.AccessRight("UID02812B", this.ZZLOGON_ID, "ADDNEW")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02812B","NotAddNewRight",this.ZZLOGON_ID));
				return _Entity;
			}

			_Entity.ATVT_CODE="ADDNEW";

				_Entity=this.Verify(_Entity);
			if (_Entity.Exceptions.Count>0)
			{
				return _Entity;
			}
			MIRDTLMEntity objAddNewEntity=new MIRDTLMEntity();

			ZZHDKeyLib objZZHDKeyLib=new ZZHDKeyLib();
			objZZHDKeyLib.Trans=this.Trans;
							objZZHDKeyLib.LNK_COLUMN("MI_NO",_Entity.MI_NO);
							objZZHDKeyLib.LNK_COLUMN_VALUE=_Entity.MI_NO;

				objZZHDKeyLib.PREFIX_CODE="UID02812B";
				objZZHDKeyLib.getSerial("MIRDTLM");
				int XSERIAL_NO=objZZHDKeyLib.PREFIX_CN;

				_Entity.MI_DT=objZZHDKeyLib.DT_NO;

				ZZTrace.Debug(ZFILE_NAME,_Entity.MI_DT);
				ZZTrace.Debug(ZFILE_NAME,XSERIAL_NO);

					objAddNewEntity.MI_DT=_Entity.MI_DT;

			this.Trans.RetrieveEntity(objAddNewEntity);

			if (objAddNewEntity.Verified)
			{
				_Entity.Exceptions.Add(new LogisticException("MI_DT","DataExist",_Entity.MI_DT));
				return _Entity;
			}else{

				objAddNewEntity.ZADD_DATE = DateTime.Now;
				objAddNewEntity.ZADD_USER = this.ZZLOGON_ID;

				_DataPermission.TABLE_NAME="MIRDTLM";
				_DataPermission.DataAccessRight();
				objAddNewEntity.ZSECURITY_CODE1 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE1");
				objAddNewEntity.ZSECURITY_CODE2 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE2");
				objAddNewEntity.ZSECURITY_CODE3 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE3");
				objAddNewEntity.ZSECURITY_CODE4 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE4");
				objAddNewEntity.ZSECURITY_CODE5 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE5");
				objAddNewEntity.ZSECURITY_CODE6 = _DataPermission.ACCESS_AUTH.getValue("SECURITY_CODE6");
				objAddNewEntity.ZSECURITY_RIGHT = _DataPermission.ACCESS_AUTH.getInteger("SECURITY_RIGHT");

				_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objAddNewEntity.ZADD_DATE);
_Entity.UZADD_USER     =objAddNewEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objAddNewEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objAddNewEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objAddNewEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objAddNewEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objAddNewEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objAddNewEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objAddNewEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objAddNewEntity.ZSECURITY_CODE6;

							objAddNewEntity.MI_NO=_Entity.MI_NO;
							objAddNewEntity.MI_DT=_Entity.MI_DT;
							objAddNewEntity.SERIAL_NO=_Entity.SERIAL_NO;
							objAddNewEntity.TRANS_WO_DT=_Entity.TRANS_WO_DT;
							objAddNewEntity.TRANS_WO_NO=_Entity.TRANS_WO_NO;
							objAddNewEntity.ITEM_NO=_Entity.ITEM_NO;
							objAddNewEntity.TRANS_UDFX1=_Entity.TRANS_UDFX1;
							objAddNewEntity.TRANS_UDFX3=_Entity.TRANS_UDFX3;
							objAddNewEntity.TRANS_UDFX4=_Entity.TRANS_UDFX4;
							objAddNewEntity.TRANS_QTY=_Entity.TRANS_QTY;
							objAddNewEntity.REFX_NO=_Entity.REFX_NO;
							objAddNewEntity.TRANS_RMK=_Entity.TRANS_RMK;
					ZZTrace.Debug(ZFILE_NAME,XSERIAL_NO);

					objAddNewEntity.SERIAL_NO=XSERIAL_NO;
					_Entity.SERIAL_NO=XSERIAL_NO;
			}

				this.Trans.SaveChanges(objAddNewEntity);

				// WriteDefault MIRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.MI_NO="+_Entity.MI_NO);
			if (!Util.IsNullOrEmpty(_Entity.MI_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(MIRHDTMEntity));//MIRHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("MI_NO",_Entity.MI_NO);
				_DataPermission.TABLE_NAME="MIRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"MIRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					MIRHDTMEntity objDMIRHDTMEntity=(MIRHDTMEntity)objEntityContainer[0];
					if (objDMIRHDTMEntity.Verified)
					{
						 _Entity.MI_NO=objDMIRHDTMEntity.MI_NO;
						 _Entity.COMP_CODE=objDMIRHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDMIRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDMIRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDMIRHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

				// WriteDefault WORDTLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_DT="+_Entity.TRANS_WO_DT);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_DT))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORDTLMEntity));//工作单明细
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_DT",_Entity.TRANS_WO_DT);
				_DataPermission.TABLE_NAME="WORDTLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORDTLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORDTLMEntity objDWORDTLMEntity=(WORDTLMEntity)objEntityContainer[0];
					if (objDWORDTLMEntity.Verified)
					{
						 _Entity.TRANS_WO_DT=objDWORDTLMEntity.WO_DT;
						 _Entity.ITEM_NO=objDWORDTLMEntity.ITEM_NO;
						 _Entity.TRANS_WO_NO=objDWORDTLMEntity.WO_NO;

					}else{
					}
			}else{
			}
			}

				// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

				_Entity.DATA_STATUS_CODE="Verified";
			return _Entity;
		}

		public  UID02812BE Update(UID02812BE _Entity)
		{

			if (_DocsPermission.AccessRight("UID02812B", this.ZZLOGON_ID, "UPDATE")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02812B","NotUpdateRight",this.ZZLOGON_ID));
				return _Entity;
			}
			_Entity.ATVT_CODE="UPDATE";

						if (_Entity.MI_DT=="")
						{
							_Entity.Exceptions.Add(new LogisticException("MI_DT","DataMiss",""));
						}

			_Entity=this.Verify(_Entity);
			ZZTrace.Debug(ZFILE_NAME,"_Entity.Exceptions.Count="+_Entity.Exceptions.Count);
			if (_Entity.Exceptions.Count>0)
			{
				return _Entity;
			}

					//ZZTrace.Debug(ZFILE_NAME,"_Entity.MI_NO="+_Entity.MI_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.MI_DT="+_Entity.MI_DT);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.SERIAL_NO="+_Entity.SERIAL_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_DT="+_Entity.TRANS_WO_DT);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_NO="+_Entity.TRANS_WO_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX1="+_Entity.TRANS_UDFX1);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX3="+_Entity.TRANS_UDFX3);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_UDFX4="+_Entity.TRANS_UDFX4);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_QTY="+_Entity.TRANS_QTY);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.REFX_NO="+_Entity.REFX_NO);
					//ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_RMK="+_Entity.TRANS_RMK);

			objRetrieveEntity=new CriteriaRetrieve(typeof(MIRDTLMEntity));
			objCondition=objRetrieveEntity.NewCondition();

					objCondition.Equals("MI_DT", _Entity.MI_DT);

			_DataPermission.UpdateCondition(objCondition);

			EntityObject objEntityObject=this.Trans.RetrieveEntity(objRetrieveEntity);

			if (objEntityObject != null)
			{
				MIRDTLMEntity objUpdateEntity=(MIRDTLMEntity)objEntityObject;
				if (objUpdateEntity.Verified)
				{
					objUpdateEntity.ZCHG_DATE=DateTime.Now;
					objUpdateEntity.ZCHG_USER=this.ZZLOGON_ID;

								objUpdateEntity.MI_NO=_Entity.MI_NO;
								objUpdateEntity.MI_DT=_Entity.MI_DT;
								objUpdateEntity.SERIAL_NO=_Entity.SERIAL_NO;
								objUpdateEntity.TRANS_WO_DT=_Entity.TRANS_WO_DT;
								objUpdateEntity.TRANS_WO_NO=_Entity.TRANS_WO_NO;
								objUpdateEntity.ITEM_NO=_Entity.ITEM_NO;
								objUpdateEntity.TRANS_UDFX1=_Entity.TRANS_UDFX1;
								objUpdateEntity.TRANS_UDFX3=_Entity.TRANS_UDFX3;
								objUpdateEntity.TRANS_UDFX4=_Entity.TRANS_UDFX4;
								objUpdateEntity.TRANS_QTY=_Entity.TRANS_QTY;
								objUpdateEntity.REFX_NO=_Entity.REFX_NO;
								objUpdateEntity.TRANS_RMK=_Entity.TRANS_RMK;

						this.Trans.SaveChanges(objUpdateEntity);

						// WriteDefault MIRHDTM
ZZTrace.Debug(ZFILE_NAME,"_Entity.MI_NO="+_Entity.MI_NO);
			if (!Util.IsNullOrEmpty(_Entity.MI_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(MIRHDTMEntity));//MIRHDTM
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("MI_NO",_Entity.MI_NO);
				_DataPermission.TABLE_NAME="MIRHDTM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"MIRHDTM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					MIRHDTMEntity objDMIRHDTMEntity=(MIRHDTMEntity)objEntityContainer[0];
					if (objDMIRHDTMEntity.Verified)
					{
						 _Entity.MI_NO=objDMIRHDTMEntity.MI_NO;
						 _Entity.COMP_CODE=objDMIRHDTMEntity.COMP_CODE;
						 _Entity.TRANS_CODE=objDMIRHDTMEntity.TRANS_CODE;
						 _Entity.TRANS_DATE=objDMIRHDTMEntity.TRANS_DATE;
						 _Entity.WH_CODE=objDMIRHDTMEntity.WH_CODE;

					}else{
					}
			}else{
			}
			}

						// WriteDefault WORDTLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.TRANS_WO_DT="+_Entity.TRANS_WO_DT);
			if (!Util.IsNullOrEmpty(_Entity.TRANS_WO_DT))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(WORDTLMEntity));//工作单明细
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("WO_DT",_Entity.TRANS_WO_DT);
				_DataPermission.TABLE_NAME="WORDTLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"WORDTLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					WORDTLMEntity objDWORDTLMEntity=(WORDTLMEntity)objEntityContainer[0];
					if (objDWORDTLMEntity.Verified)
					{
						 _Entity.TRANS_WO_DT=objDWORDTLMEntity.WO_DT;
						 _Entity.ITEM_NO=objDWORDTLMEntity.ITEM_NO;
						 _Entity.TRANS_WO_NO=objDWORDTLMEntity.WO_NO;

					}else{
					}
			}else{
			}
			}

						// WriteDefault PARTBLM
ZZTrace.Debug(ZFILE_NAME,"_Entity.ITEM_NO="+_Entity.ITEM_NO);
			if (!Util.IsNullOrEmpty(_Entity.ITEM_NO))
			{
			objRetrieveEntity=new CriteriaRetrieve(typeof(PARTBLMEntity));//物料资料主表
			objRetrieveEntity.Top=1;

			objCondition=objRetrieveEntity.NewCondition();
			objCondition.Equals("ITEM_NO",_Entity.ITEM_NO);
				_DataPermission.TABLE_NAME="PARTBLM";
				_DataPermission.AccessCondition(objCondition);
			objEntityContainer=this.Trans.RetrieveEntitys(objRetrieveEntity);

ZZTrace.Debug(ZFILE_NAME,"PARTBLM"+objEntityContainer.Count);
			if (objEntityContainer.Count>0)
			{

					PARTBLMEntity objDPARTBLMEntity=(PARTBLMEntity)objEntityContainer[0];
					if (objDPARTBLMEntity.Verified)
					{
						 _Entity.ITEM_NO=objDPARTBLMEntity.ITEM_NO;
						 _Entity.ITEM_NAME01=objDPARTBLMEntity.ITEM_NAME01;
						 _Entity.ITEM_NAME02=objDPARTBLMEntity.ITEM_NAME02;
						 _Entity.UOM_CODE=objDPARTBLMEntity.UOM_CODE;

					}else{
					}
			}else{
			}
			}

						_Entity.UZADD_DATE     =_Convert.ToDateTimeString(objUpdateEntity.ZADD_DATE);
_Entity.UZADD_USER     =objUpdateEntity.ZADD_USER;
_Entity.UZCHG_DATE     =_Convert.ToDateTimeString(objUpdateEntity.ZCHG_DATE);
_Entity.UZCHG_USER     =objUpdateEntity.ZCHG_USER;
_Entity.USECURITY_CODE1=objUpdateEntity.ZSECURITY_CODE1;
_Entity.USECURITY_CODE2=objUpdateEntity.ZSECURITY_CODE2;
_Entity.USECURITY_CODE3=objUpdateEntity.ZSECURITY_CODE3;
_Entity.USECURITY_CODE4=objUpdateEntity.ZSECURITY_CODE4;
_Entity.USECURITY_CODE5=objUpdateEntity.ZSECURITY_CODE5;
_Entity.USECURITY_CODE6=objUpdateEntity.ZSECURITY_CODE6;

					_Entity.DATA_STATUS_CODE="Verified";

				}else{
					_Entity.Exceptions.Add(new LogisticException("MI_DT","DataNotFd"));
				}
			}else{
				_Entity.Exceptions.Add(new LogisticException("MI_DT","DataNotFd"));
			}
			return _Entity;
		}

		public  UID02812BE Delete(UID02812BE _Entity)
		{
			if (_DocsPermission.AccessRight("UID02812B", this.ZZLOGON_ID, "DELETE")==false)
			{
				_Entity.Exceptions.Add(new LogisticException("UID02812B","NotDeleteRight"));
				return _Entity;
			}
			_Entity.ATVT_CODE="DELETE";

					if (_Entity.MI_DT=="")
					{
						_Entity.Exceptions.Add(new LogisticException("MI_DT","DataMiss"));
						return _Entity;
					}

				objRetrieveEntity=new CriteriaRetrieve(typeof(MIRDTLMEntity));
			objCondition=objRetrieveEntity.NewCondition();

					objCondition.Equals("MI_DT", _Entity.MI_DT);

			_DataPermission.DeleteCondition(objCondition);

			EntityObject objDeleteEntity=this.Trans.RetrieveEntity(objRetrieveEntity);

			if (objDeleteEntity != null)
			{
				if (objDeleteEntity.Verified)
				{
						this.Trans.DeleteEntity(objDeleteEntity);
						StringBuilder delete_cmd=new StringBuilder(this.ZZLOGON_ID+"UID02812B-DELETED=");
							delete_cmd.Append("MI_DT="+_Entity.MI_DT);

					ZZTrace.Debug("DELETED_LOG",delete_cmd.ToString());

				}else{
					_Entity.Exceptions.Add(new LogisticException("MI_DT","DataNotFd"));
					return _Entity;
				}
			}else{
				_Entity.Exceptions.Add(new LogisticException("MI_DT","DataNotFd"));
			}
			return _Entity;

		}

		public UID02812BE UserDefine(VContexts cMethod,UID02812BE _Entity)
		{
				return _Entity;
		}

#region Field
			private CriteriaRetrieve objRetrieveEntity;
		private List<EntityObject>  objEntityContainer;
		private Condition        objCondition;
		private ZZDefault        objDefault      = new ZZDefault();
		private ZZDataPermission _DataPermission = new ZZDataPermission();
		private ZZDocsPermission _DocsPermission = new ZZDocsPermission();
		private ZZSetting        _Setting        = new ZZSetting();
		private XConvert         _Convert        = new XConvert();

#endregion

			const  string ZFILE_NAME   ="UID02812BM";
		const  string MUKI_EDITION ="MIN";

	}
}
